<template>
	<div id="express_fee">
		<el-form :inline="true" size="medium">
			<el-form-item>
				<el-select v-model="params.storeId" placeholder="选择仓库" clearable @change="search">
					<el-option :value="item.id" :label="item.name" v-for="(item, index) in goodsStoreList"></el-option>
				</el-select>
				<el-select v-model="params.expressSheetId" placeholder="选择面单" clearable @change="search">
					<el-option :value="item.id" :label="item.shipperName+'-'+expressStatusName[item.expressStatus]" v-for="(item, index) in expressSheetList"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="search">搜索</el-button>
				<el-button type="success" @click="bathUpdateProfit()">一键修改利润</el-button>
			</el-form-item>
		</el-form>

		<el-table :data="list" v-loading="loading" stripe>
			<el-table-column label="id" prop="id" align="center"></el-table-column>
			<el-table-column label="所属仓库" align="center">
				<template slot-scope="scope">
					<span v-for="item in goodsStoreList" v-if="item.id == scope.row.store_id">{{item.name}}</span>
				</template>
			</el-table-column>
			<el-table-column label="面单" align="center">
				<template slot-scope="scope">
					{{scope.row.shipper_name+'-'+expressStatusName[scope.row.express_status]}}
				</template>
			</el-table-column>
			<el-table-column label="成本/元" prop="cost" align="center">
			</el-table-column>
			<el-table-column label="利润/元" prop="profit" align="center">
			</el-table-column>
			<el-table-column label="最大重量/kg" prop="max_weight" align="center"></el-table-column>
			<!-- <el-table-column label="备注" prop="remark" align="center"></el-table-column> -->
			<el-table-column label="创建时间" prop="createTime" align="center">
				<template slot-scope="scope">
					{{$moment(scope.row.createTime).format('Y-MM-DD HH:mm')}}
				</template>
			</el-table-column>
			<el-table-column label="操作" align="center">
				<template slot-scope="scope">
					<el-button type="text" @click="updateProfit(scope.row)">修改利润</el-button>
					<!-- <el-button type="text" class="error" @click="del(scope.row.id)">删除</el-button> -->
				</template>
			</el-table-column>
		</el-table>

		<el-pagination
			class="page"
			background
			@size-change="handleSizeChange"
			@current-change="getList"
			:current-page.sync="params.pageNo"
			:page-sizes="[10, 20, 50, 100]"
			:page-size="params.pageSize"
			layout="total, sizes, prev, pager, next, jumper"
			:total="total">
		</el-pagination>

	</div>
</template>

<script>
	export default {
		data() {
			return {
				params: {
					pageNo: 1,
					pageSize: 10,
					isCount: true,
					expressSheetId:'',
					storeId:'',
					tenantid: sessionStorage.getItem('tenantid')
				},
				list: [],
				total: 0,
				loading: false,
				formLoading: false,
				selectData: [],
				dialogVisible: false,
				formData: {
					expressSheetId: '',
					maxWeight: '',
					cost: '',

				},
				rules: {

				},
				expressStatusName:['其他面单','通用面单','菜鸟面单','拼多多面单', '京东面单'],
				goodsStoreList: [],
				expressSheetList:[],
			};
		},

		watch: {},

		created() {

		},

		mounted() {
			this.getStore();
			this.getList();
			this.getExpressSheet();
		},

		methods: {
			handleClose(done){
				this.reset()
				done();
			},

			handleSizeChange(value) {
				this.params.pageSize = value
				this.search()
			},

			search(){
				this.params.pageNo = 1
				this.params.isCount = true
				this.getList();
			},

			getList() {
				this.loading = true
				this.$request.post({
					url: '/ReportApi/tenant/expressfeelist',
					params: this.params,
					success: result =>{
						this.list = result[0]
						if(this.params.isCount){
							this.params.isCount = false
							this.total = result[1]
						}
					},
					finally: ()=>{
						this.loading = false
					}
				})
			},

			updateProfit(row){
				this.$prompt('请输入利润', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				inputPattern: /((^[1-9]\d*)|^0)(\.\d{0,2}){0,1}$/,
				inputErrorMessage: '金额格式不正确'
				}).then(({ value }) => {
					if(this.loading) return;
					this.loading = true
					this.$request.post({
						url: '/ReportApi/tenant/expressfeeupdate',
						params: {
							id:row.id,
							profit:value,
							tenantid:sessionStorage.getItem('tenantid')
						},
						success: result =>{
							this.$message.success('修改成功');
							this.getList()
						},
						finally: ()=>{
							this.loading = false
						}
					})
				}).catch(() => {
				});
			},

			

			// selectStore(storeId) {
			// 	if (!this.goodsStoreList.length) {
			// 		return;
			// 	}
			// 	return this.goodsStoreList[this.goodsStoreList.findIndex(item => item.id == storeId)].name
			// },

			getStore() {
				this.$request.post({
					closeErrInfo: true,
					closeCodeInfo: true,
					url: '/ReportApi/tenant/expressfeealllist',
					success: result => {
						this.goodsStoreList = result
					}
				})
			},

			getExpressSheet() {
				this.$request.post({
					closeErrInfo: true,
					closeCodeInfo: true,
					url: '/ReportApi/tenant/expresssheetalllistes',
					success: result => {
						this.expressSheetList = result
					}
				})
			},

			setData(data){

			},

			
		},

		beforeDestroy() {}
	}
</script>

<style>

</style>

<style lang="scss" scoped>
	.page{
		text-align: right;
		margin-top: 20px;
	}
</style>
